/*
 * Copyright (c) 2020 hebeiyiliuba.com
 * All rights reserved.
 *
 */
package org.jeecg.modules.third.tosapi.constant.enums;

import com.google.common.collect.Maps;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 货物分类绑定
 *
 * @author duanlikao
 * @created 2021/7/7
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
public enum GoodsCargoTypeEnum {

    COAL_AND_PRODUCTS("0100", "煤炭及制品","COAL_AND_PRODUCTS"),
    OIL_AND_GAS_PRODUCTS("0200", "石油、天然气及制品","OIL_AND_GAS_PRODUCTS"),
    METAL_ORE("0300", "金属矿石","METAL_ORE"),
    STEEL("0400", "钢铁","STEEL"),
    MINING_MATERIALS("0500", "矿建材料","MINING_MATERIALS"),
    CEMENT("0600", "水泥","CEMENT"),
    WOOD("0700", "木材","WOOD"),
    NON_METALLIC_ORES("0800", "非金属矿石","NON_METALLIC_ORES"),
    FERTILIZERS_AND_PESTICIDES("0900", "化肥及农药","FERTILIZERS_AND_PESTICIDES"),
    SALT("1000", "盐","SALT"),
    FOOD("1100", "粮食","FOOD"),
    MECHANICAL_EQUIPMENT_ELECTRICAL("1200", "机械、设备、电器","MECHANICAL_EQUIPMENT_ELECTRICAL"),
    LIGHT_INDUSTRY_RAW_MATERIALS_AND_PRODUCTS("1300", "轻工原料及制品","LIGHT_INDUSTRY_RAW_MATERIALS_AND_PRODUCTS"),
    NON_FERROUS_METALS("1400", "有色金属","NON_FERROUS_METALS"),
    LIGHT_INDUSTRY_PHARMACEUTICAL_PRODUCTS("1500", "轻工医药产品","LIGHT_INDUSTRY_PHARMACEUTICAL_PRODUCTS"),
    FRESH_AGRICULTURAL_PRODUCTS("1601", "鲜活农产品","FRESH_AGRICULTURAL_PRODUCTS"),
    REFRIGERATED_FROZEN_GOODS("1602", "冷藏冷冻货物","REFRIGERATED_FROZEN_GOODS"),
    COMMODITY_CAR("1702", "商品汽车","COMMODITY_CAR"),
    OTHER("1700", "其他","OTHER"),
    ;

    private  String code;
    private  String msg;

    private  String cargoClass;

    private static Map <String, GoodsCargoTypeEnum> codeMap = Maps.newHashMap();


    public String getCode() {
        return this.code;
    }

    public String getDesc() {
        return this.msg;
    }

    public String getCargoClass() {
        return this.cargoClass;
    }

    public static String getMsg(String code) {
        return codeMap.containsKey(code) ? codeMap.get(code).getDesc() : StringUtils.EMPTY;
    }

    public static boolean isValid(String code) {
        return codeMap.containsKey(code);
    }

    static {
        for (GoodsCargoTypeEnum status : GoodsCargoTypeEnum.values()) {
            codeMap.put(status.getCode(), status);
        }
    }

    public static GoodsCargoTypeEnum getCargoTypeEnumByVal(String code) {
        return Arrays.stream(GoodsCargoTypeEnum.values()).collect(Collectors.toMap(
                GoodsCargoTypeEnum::getCode, value -> value, (k1, k2) -> k2)).get(code);
    }
}
